package com.worldtolearn.webservices;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import com.worldtolearn.offer.dao.ITaxDao;
import com.worldtolearn.offer.entity.Tax;

@Path("/tax")
public class TaxService implements ITaxService {

    ITaxDao taxDao;
    
    public void setTaxDao(ITaxDao taxDaoParam) {
        taxDao = taxDaoParam;
    }

    @GET
    @Path("/rate/{country}")
    public double getTaxRate(@PathParam("country") String country){
        List<Tax> taxs = taxDao.getAllTax();
        if(!taxs.isEmpty()){
            for (Tax tax : taxs) {
                String refCountry = tax.getCountry();
                if(refCountry.equals(country)){
                    return tax.getRate();
                }
            }
        }
        return 1;
    }
}
